//
//  LabelUI.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2024/12/20.
//
import UIKit
import Foundation
public class MyLabelUI: UIViewController {
    func textDemo(_ self: AnyObject) {
        let rect = CGRect(x: 20, y: 0, width: 200, height: 30)
        let label = UILabel(frame:rect)
        label.text = "我是一个普通的便签控件"
        self.addSubview(label)
        
        // 创建自定义UILabel控件
        let rect2 = CGRect(x: 20, y: 160, width: 300, height: 30)
        let label2 = UILabel(frame: rect2)
        label2.text = "我是一个自定义便签控件"
        label2.textColor = UIColor.red
        label2.shadowColor = UIColor.green
        label2.shadowOffset = CGSize(width: 2, height: 2)
        label2.textAlignment = NSTextAlignment.center
        label2.backgroundColor = UIColor.blue
        self.addSubview(label2)
        
        // 丰富多彩的UILabel控件
        let rect3 =  CGRect(x:20, y:210, width: 200,height: 250)
        let label3 = UILabel(frame: rect3)
        label3.text = "我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本我是多行文本"
        label3.numberOfLines = 7
        label3.backgroundColor = UIColor.green
        self.addSubview(label3)
        
        // 针对个别文字个性化处理
        let rect4 = CGRect(x: 20, y: 470, width: 200, height: 30)
        let label4 = UILabel(frame: rect4)
        let attri = NSMutableAttributedString(string: "我是个性化文本")
        let range = NSRange(location: 0, length: 2)
        // 设置个性化样式
        attri.addAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 20), NSAttributedString.Key.foregroundColor: UIColor.red, NSAttributedString.Key.backgroundColor: UIColor.green, NSAttributedString.Key.underlineStyle: NSNumber(2), NSAttributedString.Key.underlineColor: UIColor.black], range: range)
        
        attri.addAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 13),NSAttributedString.Key.foregroundColor: UIColor.blue], range: NSRange(location: 3, length: 3))
        label4.attributedText = attri
        self.addSubview(label4)
    }
}

